package org.example.chapter2;

import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.functions.Action1;

public class DemoA {
    public static void main(String[] args) {
        DemoA demoa = new DemoA();
        demoa.getObservable();
    }

    private Observer<String> getObserver1(){
        Observer<String> observer = new Observer<String>() {
            @Override
            public void onCompleted() {
                System.err.println("Completed");
            }

            @Override
            public void onError(Throwable throwable) {
                System.err.println("Error");
            }

            @Override
            public void onNext(String s) {
                System.err.println("Item: " + s);
            }

        };
        return observer;
    }

    private Observer<String> getObserver2(){
        Subscriber<String> subscriber = new Subscriber<String>() {
            @Override
            public void onCompleted() {

            }

            @Override
            public void onError(Throwable throwable) {

            }

            @Override
            public void onNext(String s) {

            }

            @Override
            public void onStart() {
                super.onStart();
            }
        };
        return null;
    }

    private void getObservable(){
        Observable.create(new Observable.OnSubscribe<String>() {
            @Override
            public void call(Subscriber<? super String> subscriber) {
                subscriber.onNext("hello");
                subscriber.onNext(" World");
                subscriber.onNext(" JohnConnor");
                subscriber.onCompleted();
            }
        }).subscribe(new Action1<String>() {
            @Override
            public void call(String s) {
                System.err.println(s);
            }
        });
    }
}
